package com.shengqiang.cloud.ups.controller;

import com.shengqiang.cloud.ups.common.model.JsonResult;
import com.shengqiang.cloud.ups.common.model.PageResult;
import com.shengqiang.cloud.ups.dao.modal.UpmsRole;
import com.shengqiang.cloud.ups.service.UpmsRoleWebService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/1.
 */
@Controller
@RequestMapping(value = "role")
public class UpmsRoleController {

    @Autowired
    private UpmsRoleWebService service;

    @RequestMapping(value = "toRole",method = {RequestMethod.POST,RequestMethod.GET})
    public String toRolePage(){
        return "/user/role";
    }

    @RequiresPermissions(value = "upms:users:role:add")
    @ResponseBody
    @RequestMapping(value = "/addRole",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult addRole(UpmsRole role){
        return service.addRole(role);
    }

    @RequiresPermissions(value = "upms:users:role:list")
    @ResponseBody
    @RequestMapping(value = "/selectRoles",method = {RequestMethod.POST,RequestMethod.GET})
    public PageResult<UpmsRole> selectRoles(@RequestParam Map<String,Object> params){
        return service.selectRoles(params);
    }

    @RequiresPermissions(value = "upms:users:role:list")
    @ResponseBody
    @RequestMapping(value = "selectAllRoles",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult<List<UpmsRole>> selectAllRoles(@RequestParam Map<String,Object> params){
        return  service.selectAllRoles(params);
    }

    @RequiresPermissions(value = "upms:users:role:delete")
    @ResponseBody
    @RequestMapping(value = "/deleteRoles",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteRoles(@RequestParam("roleIds[]") List<Integer> roleIds){
        return service.deleteRoleByIds(roleIds);
    }

    @RequiresPermissions(value = "upms:users:role:edit")
    @ResponseBody
    @RequestMapping(value = "updateRole",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult updateRole(UpmsRole role){
        return service.updateRoleById(role);
    }
}
